﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.DAO;
using DHQGHN.DAL.DAO.MappingDB;
using DHQGHN.DAL.DataMapper;
using DHQGHN.DAL.Models;
using DHQGHN.DAL.Models.MappingDB;

namespace DHQGHN.DAL.BO.MappingDB
{
    public class SD_MappingColumnBO : BaseBO
    {
        #region Field Name in return DataSet
      
      
        //Field Name in return DataSet
        public const string Field_MappingColumnId = "MappingColumnId";
        public const string Field_MappingTableId = "MappingTableId";
        public const string Field_ConfigSourceID = "ConfigSourceID";
        public const string Field_ConfigDestinationID = "ConfigDestinationID";
        public const string Field_SourceTable = "SourceTable";
        public const string Field_DestinationTable = "DestinationTable";

        public const string Field_SourceColumnName = "SourceColumnName";
        public const string Field_SourceColumnType = "SourceColumnType";
        public const string Field_SourceColumnNull = "SourceColumnNull";
        public const string Field_SourceColumnSize = "SourceColumnSize";
        public const string Field_SourceColumnPrecision = "SourceColumnPrecision";
        public const string Field_SourceColumnScale = "SourceColumnScale";
        public const string Field_DestinationColumnName = "DestinationColumnName";
        public const string Field_DestinationColumnType = "DestinationColumnType";
        public const string Field_DestinationColumnNull = "DestinationColumnNull";
        public const string Field_DestinationColumnSize = "DestinationColumnSize";
        public const string Field_DestinationColumnPrecision = "DestinationColumnPrecision";
        public const string Field_DestinationColumnScale = "DestinationColumnScale";
       

        
        #endregion


        public String _connectionString;
        private SD_MappingColumnDAO _shareDAO;
        public SD_MappingColumnBO(string connString)
        {
            this._connectionString = connString;

        }
        public SD_MappingColumnBO()
        {
            this._connectionString = DEFAULT_CONN_STRING;

        }

        public SD_MappingColumnDAO CreateSQLDAO()
        {
            return new SD_MappingColumnDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public List<SD_MappingColumn> GetAllColumnInfoByMappingTableId(int mappingColumnId)
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {SD_MappingColumn.Field_MappingColumnId,Field_MappingColumnId},
					{SD_MappingColumn.Field_MappingTableId,Field_MappingTableId},
                    {SD_MappingColumn.Field_ConfigSourceID,Field_ConfigSourceID},
                    {SD_MappingColumn.Field_ConfigDestinationID,Field_ConfigDestinationID},
                    {SD_MappingColumn.Field_SourceTable,Field_SourceTable},
                    {SD_MappingColumn.Field_DestinationTable,Field_DestinationTable},

                    {SD_MappingColumn.Field_SourceColumnName,Field_SourceColumnName},
                    {SD_MappingColumn.Field_SourceColumnNull,Field_SourceColumnNull},
					{SD_MappingColumn.Field_SourceColumnPrecision,Field_SourceColumnPrecision},
					{SD_MappingColumn.Field_SourceColumnScale,Field_SourceColumnScale},
					{SD_MappingColumn.Field_SourceColumnSize,Field_SourceColumnSize},
					{SD_MappingColumn.Field_SourceColumnType,Field_SourceColumnType},  

                     {SD_MappingColumn.Field_DestinationColumnName,Field_DestinationColumnName},
                    {SD_MappingColumn.Field_DestinationColumnNull,Field_DestinationColumnNull},
					{SD_MappingColumn.Field_DestinationColumnPrecision,Field_DestinationColumnPrecision},
					{SD_MappingColumn.Field_DestinationColumnScale,Field_DestinationColumnScale},
					{SD_MappingColumn.Field_DestinationColumnSize,Field_DestinationColumnSize},
					{SD_MappingColumn.Field_DestinationColumnType,Field_DestinationColumnType},                
                    
                };
                return _shareDAO.GetAllColumnInfoByMappingTableId(mappingColumnId, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public List<SD_MappingColumn> GetAllColumnInfoMetadataByTableName(int mappingTableId, string tableName)
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
					{SD_MappingColumn.Field_MappingTableId,Field_MappingTableId},
                    {SD_MappingColumn.Field_SourceColumnName,Field_SourceColumnName},
                    {SD_MappingColumn.Field_SourceColumnNull,Field_SourceColumnNull},
					{SD_MappingColumn.Field_SourceColumnPrecision,Field_SourceColumnPrecision},
					{SD_MappingColumn.Field_SourceColumnScale,Field_SourceColumnScale},
					{SD_MappingColumn.Field_SourceColumnSize,Field_SourceColumnSize},
					{SD_MappingColumn.Field_SourceColumnType,Field_SourceColumnType},                                   
                    {SD_MappingColumn.Field_DestinationTable,Field_DestinationTable},                                   
                    
                };
                return _shareDAO.GetAllColumnInfoMetadataByTableName(mappingTableId, tableName, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public SD_MappingColumn GetColumnMappingBySouceColumnName(int mappingTableId, string souceColumnName)
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
					{SD_MappingColumn.Field_MappingColumnId,Field_MappingColumnId},
                    {SD_MappingColumn.Field_DestinationColumnName,Field_DestinationColumnName},
                    {SD_MappingColumn.Field_DestinationColumnNull,Field_DestinationColumnNull},
					{SD_MappingColumn.Field_DestinationColumnPrecision,Field_DestinationColumnPrecision},
					{SD_MappingColumn.Field_DestinationColumnScale,Field_DestinationColumnScale},
					{SD_MappingColumn.Field_DestinationColumnSize,Field_DestinationColumnSize},
					{SD_MappingColumn.Field_DestinationColumnType,Field_DestinationColumnType},                                   
                    
                };
                return _shareDAO.GetColumnMappingBySouceColumnName(mappingTableId, souceColumnName, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public SD_MappingColumn Save(SD_MappingColumn model)
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                return _shareDAO.Save(model);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public int Delete(int mappingColumnId)
        {
            try
            {
                _shareDAO = CreateSQLDAO();
                return _shareDAO.Delete(mappingColumnId);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
